package com.jn.mvp.views;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.mvp.R;
import com.jn.mvp.adapter.TopNewsAdapter;
import com.jn.mvp.contact.TopNewsContact;
import com.jn.mvp.entity.TopNews;
import com.jn.mvp.presenter.TopNewsPresenter;

import java.util.ArrayList;
import java.util.List;

public class TopNewsActivity extends AppCompatActivity implements TopNewsContact.TopNewsView , View.OnClickListener {
    private TextView wt1 , wt2 , wt3 , wt4 , wt5 , wt6 , wt7 , wt8, wt9 , wt10;
    private RecyclerView wt_list;
    private TopNewsAdapter adapter;
    private TopNewsContact.TopNewsPresenter presenter;
    private List<TopNews.Result.Data> mList ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_top_news);
        init();
    }

    @Override
    public void showData(TopNews topNews) {
        Log.d("走到了此处", "========================== ");
        mList = topNews.getResult().getData();
        Log.e("数据数量", String.valueOf(mList.size()));
        adapter.updateDate(mList);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.wt1){
            presenter.getData("top");
            wt1.setSelected(true);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt2){
            presenter.getData("shehui");
            wt1.setSelected(false);
            wt2.setSelected(true);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt3){
            presenter.getData("guonei");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(true);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt4){
            presenter.getData("guoji");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(true);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt5){
            presenter.getData("yule");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(true);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt6){
            presenter.getData("tiyu");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(true);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        } else if (id == R.id.wt7) {
            presenter.getData("junshi");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(true);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt8){
            presenter.getData("keji");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(true);
            wt9.setSelected(false);
            wt10.setSelected(false);
        }else if (id == R.id.wt9){
            presenter.getData("caijing");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(true);
            wt10.setSelected(false);
        } else if (id == R.id.wt10) {
            presenter.getData("shishang");
            wt1.setSelected(false);
            wt2.setSelected(false);
            wt3.setSelected(false);
            wt4.setSelected(false);
            wt5.setSelected(false);
            wt6.setSelected(false);
            wt7.setSelected(false);
            wt8.setSelected(false);
            wt9.setSelected(false);
            wt10.setSelected(true);
        }

    }

    private void init(){
        wt1 = findViewById(R.id.wt1);
        wt2 = findViewById(R.id.wt2);
        wt3 = findViewById(R.id.wt3);
        wt4 = findViewById(R.id.wt4);
        wt5 = findViewById(R.id.wt5);
        wt6 = findViewById(R.id.wt6);
        wt7 = findViewById(R.id.wt7);
        wt8 = findViewById(R.id.wt8);
        wt9 = findViewById(R.id.wt9);
        wt10 = findViewById(R.id.wt10);
        wt_list = findViewById(R.id.w_list);
        wt1.setSelected(true);
        presenter = new TopNewsPresenter(this , this);
        presenter.getData("top");
        wt_list.setLayoutManager(new GridLayoutManager(this, 1));
        mList = new ArrayList<>();
        adapter = new TopNewsAdapter(mList , this , this);
        wt_list.setAdapter(adapter);

        wt1.setOnClickListener(this);
        wt2.setOnClickListener(this);
        wt3.setOnClickListener(this);
        wt4.setOnClickListener(this);
        wt5.setOnClickListener(this);
        wt6.setOnClickListener(this);
        wt7.setOnClickListener(this);
        wt8.setOnClickListener(this);
        wt9.setOnClickListener(this);
        wt10.setOnClickListener(this);
    }
}
